// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Router from 'vue-router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import VCharts from 'v-charts'
import '@/styles/index.scss' // global css
import store from './store'

import '@/icons' // icon
import '@/permission' // permission control
import axios from 'axios'

Vue.prototype.$axios = axios

Vue.use(ElementUI)
// Vue.use(VCharts)

const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
//深拷贝
Vue.prototype.$deepClone = (json)=>{
  if (!json){
    return json;
  }
  return JSON.parse(JSON.stringify(json))
}
// 图片转为base64
// Vue.prototype.$base64Img = (e) => {
//   return new Promise(function (resolve, reject) { // 使用Promise进行异步处理
//     let fileSize = 0
//     let fileMaxSize = 2048 // 设置图片最大为 2M
//     fileSize = e.target.files[0].size // 获取图片大小
//     let size = fileSize / 1024
//     let file = e.target.files[0] // 获取图片文件对象
//     let reader = new FileReader() // 实例化一个对象
//     if (size > fileMaxSize) {
//       e.target.value = '' // 内容清空
//       resolve({err: '图片大小必须小于2M！'})
//     } else if (size <= 0) {
//       e.target.value = '' // 内容清空
//       resolve({err: '图片大小大小不能为0M！'})
//     } else {
//       reader.readAsDataURL(file) // 把图片文件对象转换base64
//       reader.onload = function (e) {
//         resolve(e.target.result) // 回到函数返回base64值
//       }
//     }
//   })
// }

// import Chat from 'jwchat';
// import 'jwchat/lib/JwChat.css';
// Vue.use(Chat)

Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
